package demo;

import java.util.Scanner;

/**
 * 计算器demo
 * <p>
 * Version: 1.0
 * Author: 瓶子
 */
public class Calculator {
    public static void main( String[] args ) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入对应符号选择计算方式 + - * / ");
        String type = scanner.next();
        //type不在给定方式内
        if (!type.equals("+") && !type.equals("-") && !type.equals("*") && !type.equals("/")) {
            System.out.println("计算类型选择错误，请输入正确内容");
            return;
        }

        System.out.println("请输入第一个数字进行计算：");
        int a = scanner.nextInt();

        System.out.println("请输入第二个数字进行计算：");
        int b = scanner.nextInt();

        switch ( type ) {
            case "+":
                System.out.println("结果为：" + sum(a, b));
                break;
            case "-":
                System.out.println("结果为：" + sub(a, b));
                break;
            case "*":
                System.out.println("结果为：" + mul(a, b));
                break;
            case "/":
                System.out.println("结果为：" + div(a, b));
                break;
        }
    }

    /**
     * 加法计算
     * param int a,b
     * return int
     * <p>
     * Version: 1.0
     * Author: 瓶子
     */

    public static int sum( int a, int b ) {
        return a + b;
    }

    /**
     * 减法计算
     * param int a,b
     * return int
     * <p>
     * Version: 1.0
     * Author: 瓶子
     */
    public static int sub( int a, int b ) {
        return a - b;
    }

    /**
     * 乘法计算
     * param int a,b
     * return int
     * <p>
     * Version: 1.0
     * Author: 瓶子
     */
    public static int mul( int a, int b ) {
        return a * b;
    }

    /**
     * 除法计算
     * param int a,b
     * return int
     * <p>
     * Version: 1.0
     * Author: 瓶子
     */
    public static int div( int a, int b ) {
        if (b == 0) {
            System.out.println("除数不能为0");
            return 0;
        }
        return a / b;
    }

}
